Load libraries

## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## Loading required package: lubridate
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## == Need to Learn tidyquant? ====================================================
## Business Science offers a 1-hour course - Learning Lab #9: Performance Analysis & Portfolio Optimization with tidyquant!
## </> Learn more at: https://university.business-science.io/p/learning-labs-pro </>
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.4     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x lubridate::as.difftime() masks base::as.difftime()
## x lubridate::date()        masks base::date()
## x dplyr::filter()          masks stats::filter()
## x xts::first()             masks dplyr::first()
## x lubridate::intersect()   masks base::intersect()
## x dplyr::lag()             masks stats::lag()
## x xts::last()              masks dplyr::last()
## x lubridate::setdiff()     masks base::setdiff()
## x lubridate::union()       masks base::union()

Date Calculations

Data Processing

Downloading S & P 500 price

January 16, 2021

library(plotly)

plot_ly(index) %>%
              add_trace(x =~date, y=~volume, type='bar', name = 'Volume',
                        marker = list(color = '#90EE90'),
                        hoverinfo = "text",
                        text = ~paste(volume), '') %>%
              add_trace(x = ~date, y = ~close, type="scatter", mode = "lines", 
                        name = 'Index', yaxis = 'y2',
                        line = list(color = ' #013220'),
                        hoverinfo = "text",
                        text = ~paste('$',close)) %>% 
             layout(title = "S & P 500",
                    xaxis = list(title = "Date"),
                    yaxis = list(side = 'right', title = 'Volume', 
                                 showgrid = FALSE, zeroline = FALSE),
                    yaxis2 = list(side = 'left', overlaying = "y", 
                                  title = 'Price in USD', showgrid = TRUE,
                    zeroline = FALSE))

January 16, 2021